package  
{
	/**
	 * ...
	 * @author Martina Rasch
	 */
	
	import net.flashpunk.Entity;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.utils.Input;
	import net.flashpunk.FP;
	import net.flashpunk.graphics.Spritemap;
	import net.flashpunk.graphics.Text;

	public class Button extends Entity
	{
		[Embed(source = 'res/startButton.png')] private const BUTTON:Class;
		private static var camX:int = 0;
		private static var camY:int = 0;
		private var text1:Text;
		private var ability:int = 0;
		
		private static var width:int;
		private static var height:int;
		
		private var button:Spritemap = new Spritemap(BUTTON, 300, 60);
		
		public function Button(nx:int, ny:int, buttonText:String = " ", xOff:int = 0, ability:int = 0, width:int = 800, height:int = 600) 
		{
			this.width = width;
			this.height = height;
			this.ability = ability;
			text1 = new Text(buttonText, xOff, 15, 300, 60);
			addGraphic(text1);
			text1.color = 0xFFFFFF;
			text1.size = 30;
			//text1 = new Text("Spiel starten", 0, 0, 300, 60);
			//addGraphic(new Text("Spiel starten", 0, 0));
			x = nx;
			y = ny;
			addGraphic(button);
			addGraphic(text1);
			trace(nx, ny);
			
			button.add("away", [0], 20, true); 
			button.add("over", [1], 20, true);
		}
		
		override public function update():void {
			super.update();
			camX =Input.mouseX;
			camY = Input.mouseY;
			if (camX < x + 300 && camX > x && camY < y + 60 && camY > y) {
				button.play("over");
				if (Input.mousePressed)
				{
					if (ability == 0) {
						//trace(camX + " " + camY);
						trace("button pressed");
						FP.world = new Level1(width, height);
					} else if (ability == 1) {
						FP.world = new BGWorld(new Tutorial, width, height);
					} else if (ability == 2) {
						FP.world = new Highscore(width, height, -1);
					} else {
						FP.world = new BGWorld(new CreditsBackground, width, height);
					}
				}
			} else {
				button.play("away");
			}
		}
	}

}